<?php
require("../config.php");
$autocomplete = $_GET['query'];
$query = mysql_query("SELECT * FROM alumnos WHERE apellidos LIKE '%".$autocomplete."%'");
$num_rows = mysql_num_rows($query);

$regresar = "{ 
 query:'".$autocomplete."',";
$regresar .= "suggestions:[";
if ($num_rows>0) {
    $i = 1;
    while ($row = mysql_fetch_array($query)) {
            $result = $row['apellidos'];
            if ($i==$num_rows) {
                $regresar .= "'".$result."'";
            } else {
                $regresar .= "'".$result."',";
            }
            $i++;
        }
      }
$regresar .= "] }";

echo $regresar;
?>